package context

import "fmt"

//接口链式日志对象
type ChainInfo struct {
	RequestInfo  `xorm:"extends"`
	Host         string `json:"host"`
	CreateTime   int64  `json:"createTime"`
	Parameter    string `json:"parameter"`
	ErrorInfo    string `json:"errorInfo"`
	Response     string `json:"response"`
	Memo         string `json:"memo"`
	ResponseTime int    `json:"responseTime"`
}

func (c *ChainInfo) Reset(ctx *Context) {
	pm := ""
	for _, v := range *ctx.Request.Params() {
		pm += "\n"
		pm += fmt.Sprintf("%v：%v", v.Name, v.Value)
	}

	//数据库没有对应字段，人工登记到parameter
	pm += fmt.Sprintf("%v：%v", "sessionKey", ctx.Request.Info.SessionKey)

	c.RequestInfo = ctx.Request.Info
	//c.Host = ""
	c.CreateTime = ctx.RequestTime.Unix()
	c.Parameter = pm
	c.ErrorInfo = ""
	c.Response = ""
	c.Memo = ""
	c.ResponseTime = 0
}
